<template>
	<view class="page-box">
		<!-- <an-nav-bar title="按个摩">
			<template :slot="'left'">
				<view class="coordinate" @click="GotoUrl('/pages/location/location')">
					<uni-icons type="location-filled" size="20" color="#fff"></uni-icons>
					<view class="text">{{$mStore.state.location.name}}</view>
					<uni-icons type="bottom" size="20" color="#fff"></uni-icons>
				</view>
			</template>
		</an-nav-bar> -->
		<view class="nav">
			<view class="coordinate" @click="GotoUrl('/pages/location/location')">
				<uni-icons type="location-filled" size="20" color="#fff"></uni-icons>
				<view class="text">{{$mStore.state.location.name || '未获取定位'}}</view>
				<uni-icons type="bottom" size="20" color="#fff"></uni-icons>
			</view>
			<view class="title">
				<!-- <image src="/static/image/logo-word.png" mode="widthFix"></image> -->
			</view>
		</view>
		<view style="height:calc(var(--status-bar-height) + 88rpx) ;"></view>
		<view class="home-page">
			<view class="bannar">
				<swiper :indicator-dots="swiperList.length > 1">
					<swiper-item v-for="(item,index) in swiperList" :key="index">
						<image :src="$common.binImage(item.imgUrl,1,1)" mode="aspectFill"></image> >
					</swiper-item>
				</swiper>
			</view>
			<view class="officialLabel" @click="GotoUrl('/pages/guarantee/guarantee')">
				<view class="">
					<image src="/static/label_icon.png" mode=""></image>
					<text>平台担保</text>
				</view>
				<view class="">
					<image src="/static/label_icon.png" mode=""></image>
					<text>官方认证</text>
				</view>
				<view class="">
					<image src="/static/label_icon.png" mode=""></image>
					<text>收费透明</text>
				</view>
				<view class="">
					<image src="/static/label_icon.png" mode=""></image>
					<text>爽约包退</text>
				</view>
			</view>
			<scroll-view class="menu-scroll-view" scroll-x>
				<view class="menu-item" v-for="(menu,index) in menuList" :key="index" @click="GotoUrl(menu.url)">
					<image :src="'/static/menu/' +  menu.icon" mode=""></image>
					<view>{{menu.label}}</view>
				</view>
			</scroll-view>
			<!-- 	<view class="menu-box flex_sw">
				<view class="menu-item" v-for="(menu,index) in menuList" :key="index" @click="GotoUrl(menu.url)">
					<image :src="'/static/menu/' +  menu.icon" mode=""></image>
					<view>{{menu.label}}</view>
				</view>
			</view> -->
			<view class="bidian">
				<view class="b_title ">
					<view class="b_title_l">
						<!-- <image class="heart" src="/static/heart.png" mode=""></image> -->
						<text>必点技师</text>
					</view>
					<view class="b_title_r flex iconfont" @click="GotoUrl('/pages/technician/reliable?title=必点技师')">
						<text>查看更多</text>
						<!-- <image class="more" src="/static/more.png" mode=""></image> -->
					</view>
				</view>
				<view class="b_list">
					<view class="b_list_item" v-for="(item,index) in speciaTechnician" :key="index"
						@click="GotoUrl('/pages/technicianDetail/technicianDetail?id=' + item.id)">
						<image class="item_img" :src="$common.binImage(item.headImg)" mode="aspectFill"></image>
						<view class="info">
							<view class="b_data ">
								<view class="">{{item.nickName}}</view>
								<view class="">{{$common.distance(item.distance)}}</view>
							</view>
							<button class="b_btn">预约</button>
						</view>
					</view>
				</view>
			</view>
			<view class="advert">
				<swiper class="advert-swiper">
					<swiper-item v-for="(item,index) in 1" :key="index">
						<image src="/static/ibannar.jpg" alt=""></image> >
					</swiper-item>
				</swiper>
			</view>
			<view class="technician">
				<view class="tabbar">
					<!-- <view :class="{'active-tabbar':tabIndex == 1}" @click="onTabr(1)">头牌</view> -->
					<view :class="{'active-tabbar':tabIndex == 2}" @click="onTabr(2)">附近</view>
					<view :class="{'active-tabbar':tabIndex == 3}" @click="onTabr(3)">新人</view>
				</view>
				<view class="list" v-show="technicianList.length">
					<view class="list-item" v-for="(item,index) in technicianList" :key="index"
						@click="GotoUrl('/pages/technicianDetail/technicianDetail?id=' + item.id)">
						<image class="image" :src="$common.binImage(item.headImg)" mode="aspectFill"></image>
						<view class="info">
							<view class="">{{item.nickName}}</view>
							<view class="">
								<text class="t1">{{$common.distance(item.distance)}}</text>
								<!-- <text class="t2">/{{item.nickName}}</text> -->
							</view>
						</view>
						<view class="distance">
						</view>
					</view>
				</view>
				<view class="list " v-if="!technicianList.length">
					<view class="null-box">
						<image src="/static/null.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		
		<Upgrade ref="refUpgrade" />
	</view>
</template>

<script>
	import indexConfig from '@/config/index.config';
	import Upgrade from "@/components/upgrade"
	
	export default {
		components: {
			Upgrade,
		},
		data() {
			return {
				latitude:'',
				longitude:'',
				imgUrl: indexConfig.imgUrl,
				tabIndex: 2,
				cityName: "",
				swiperList: [],
				technicianList: [],
				speciaTechnician: [],
				menuList: [{
						label: "附近门店",
						icon: "menu-7.png",
						url: '/pages/technician/store'
						// }, {
						// 	label: "每日特价",
						// 	icon: "menu-8.png",
						// 	url: '/pages/technician/todayPrice'
						// }, {
						// 	label: "附近技师",
						// 	icon: "menu-1.png",
						// 	url: '/pages/technician/nearby'
				}, {
					label: "上门服务",
					icon: "menu-2.png",
					url: '/pages/technician/product'
				}, {
					label: "靠谱专区",
					icon: "menu-3.png",
					url: '/pages/technician/reliable'
				}, {
					label: "特惠专区",
					icon: "menu-4.png",
					url: '/pages/technician/discount'
					// }, {
					// 	label: "常见问题",
					// 	icon: "menu-6.png",
					// 	url: '/pages/technician/reliable'
				}, {
					label: "领券中心",
					icon: "menu-5.png",
					url: '/pages/technician/coupon'
				},]
			};
		},
		onLoad() {
			uni.setTabBarStyle({
				//"backgroundColor": "#0F0E0C",
				"color": "#B8B8B8",
				"selectedColor": "#FFFFFF",
			})
		},
		onShow() {
			uni.setTabBarStyle({
				//"backgroundColor": "#0F0E0C",
				"color": "#B8B8B8",
				"selectedColor": "#FFFFFF",
			})
			
			let {
				location
			} = this.$mStore.state
			this.latitude = location.latitude
			this.longitude = location.longitude
			
			this.$http.get('/appNoAuth/config/configSlider/list').then(res => {
				this.swiperList = res.data
			})
			this.$http.get('/appNoAuth/store/massageTechnician/list', {
				pageNum: 1,
				pageSize: 3,
				status: 1,
				accountType: 1,
				mustStatus: 1,
				latitude:this.latitude,
				longitude:this.longitude,
			}).then(res => {
				this.speciaTechnician = res.rows
			})
			this.getList()
		},
		onReady() {
			this.$refs.refUpgrade.autoCheck()
		},
		methods: {
			onTabr(idx) {
				this.tabIndex = idx
				this.technicianList = []
				this.getList()
			},
			GotoUrl(url) {
				uni.navigateTo({
					url: url
				})
			},
			getList() {
				let obj = {
					status: 1,
				}
				if (this.tabIndex == 1) {
					obj.redStatus = 1
				}
				if (this.tabIndex == 2) {
					obj.latitude = this.latitude
					obj.longitude = this.longitude
				}
				if (this.tabIndex == 3) {
					obj.newStatus = 1
				}
				this.$http.get('/appNoAuth/store/massageTechnician/list', {
					accountType: 1,
					...obj
				}).then(res => {
					this.technicianList = res.rows
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.nav {
		width: 100%;
		height: calc(var(--status-bar-height) + 88rpx);
		position: fixed;
		left: 0;
		top: 0;
		//background: #0F0E0C;
		z-index: 999;
		box-sizing: border-box;
		padding-top: var(--status-bar-height);
		display: flex;
		align-items: center;
		justify-content: center;

		.title {
			width: 174rpx;
			height: 40rpx;

			image {
				width: 100%;
				background: none;
			}
		}

		.coordinate {
			position: absolute;
			left: 32rpx;
			top: var(--status-bar-height);
		}
	}

	.home-page {
		padding: 0 30rpx;



		.technician {
			padding-bottom: 20rpx;

			.list {
				display: flex;
				flex-wrap: wrap;

				.list-item {
					width: 336rpx;
					height: 350rpx;
					margin-top: 18rpx;
					position: relative;

					.distance {
						width: 337rpx;
						height: 350rpx;
						position: absolute;
						top: 0;
						left: 0;
						background: rgba(0, 0, 0, .3);
						z-index: 99;
					}

					.info {
						width: 100%;
						padding: 0 10rpx;
						box-sizing: border-box;
						position: absolute;
						left: 0;
						bottom: 20rpx;

						>view {
							&:first-child {
								height: 40rpx;
								font-size: 28rpx;
								font-weight: 700;
								color: #ffffff;
								line-height: 40rpx;
							}

							.t1 {
								color: #FFD68E;
							}

							.t2 {
								color: #FFFFFF;
							}

							&:last-child {
								height: 28rpx;
								font-size: 20rpx;
								font-weight: 500;
								line-height: 28rpx;
							}
						}
					}

					.image {
						width: 100%;
						height: 100%;
						border-radius: 20rpx;
						background: none;
					}

					&:nth-child(odd) {
						margin-right: 18rpx;
					}
				}
			}

			.tabbar {
				display: flex;
				align-items: center;
				height: 80rpx;
				// box-shadow: 0 0 4rpx 0 rgba(51, 51, 51, .09);
				// background-color: #fff;

				>view {
					flex: 1;
					text-align: center;
					height: 80rpx;
					line-height: 80rpx;
					color: #9E9E9E;
					font-size: 28rpx;
					font-weight: 400;
				}

				.active-tabbar {
					color: #FFFFFF;
					position: relative;

					&::after {
						position: absolute;
						left: 50%;
						-webkit-transform: translateX(-50%);
						transform: translateX(-50%);
						bottom: 14rpx;
						width: 88rpx;
						height: 4rpx;
						background: linear-gradient(276deg, #aa8050 0%, #d7b075 100%);
						border-radius: 2rpx;
						content: "";
					}
				}
			}
		}

		.advert {
			height: 160rpx;
			margin: 28rpx 0;

			.advert-swiper {
				width: 100%;
				height: 160rpx;

				swiper-item,
				image {
					width: 100%;
					height: 100%;
					border-radius: 10rpx;
				}
			}
		}

		.bidian {
			width: 100%;
			height: 378rpx;
			background: url(/static/bidian.png) no-repeat center;
			background-size: 100% auto;
			border-radius: 20rpx 20rpx 0 0;
			position: relative;
			padding: 0 28rpx;
			box-sizing: border-box;


			.b_list {
				display: flex;
				align-items: center;
				overflow: hidden;

				.b_list_item {
					width: 192rpx;
					height: 268rpx;
					position: relative;
					margin-right: 28rpx;
					border-radius: 20rpx;

					&::after {
						background: linear-gradient(0deg, #0f0e0c 0%, rgba(0, 0, 0, 0.00));
						/* 定位子绝父相 */
						position: absolute;
						/* 定位子绝父相 */
						width: 192rpx;
						height: 268rpx;
						/* 注意伪元素作为子元素盒子用绝对定位并且宽高和要覆盖的父级元素一致 */
						content: "";
						top: 0;
						left: 0;
					}

					.item_img {
						width: 192rpx;
						height: 268rpx;
						border-radius: 20rpx;
					}

					.info {
						position: absolute;
						left: 0;
						bottom: 0;
						width: 192rpx;
						height: 138rpx;
						border-radius: 0 0 20rpx 20rpx;
						z-index: 99;

						.b_data {
							display: flex;
							padding: 40rpx 10rpx 10rpx;
							font-weight: 500;
							box-sizing: border-box;
							justify-content: space-between;

							>view {
								line-height: 38rpx;

								&:last-child {
									color: rgba(255, 255, 255, 0.50);
									font-size: 20rpx;
								}

								&:first-child {
									color: #FFFFFF;
									font-size: 24rpx;
									width: 50%;
									word-break: keep-all;
									white-space: nowrap;
									overflow: hidden;
									text-overflow: ellipsis;
								}
							}
						}

						.b_btn {
							width: 152rpx;
							height: 40rpx;
							background: linear-gradient(285deg, #aa8050 0%, #d7b075 100%);
							border-radius: 8rpx;
							line-height: 40rpx;
							text-align: center;
							font-size: 20rpx;
							font-weight: 400;
							color: #fff;

							&::after {
								border: none;
							}
						}
					}
				}
			}

			.b_title {
				display: flex;
				align-items: center;
				padding: 24rpx 0;

				.b_title_r {
					display: flex;
					align-items: center;

					font-size: 24rpx;
					font-weight: 500;
					color: rgba(#ffffff, .5);

					&::after {
						content: '\e65f';
						font-weight: bold;
						font-size: 16rpx;
						margin-left: 4rpx;
						color: rgba(#ffffff, .5);
						transform: translateY(-1rpx);
					}
				}

				.b_title_l {
					flex: 1;
					display: flex;
					align-items: center;
					font-size: 32rpx;
					font-weight: 700;
					color: #ffffff;

					.heart {
						width: 32rpx;
						height: 32rpx;
						margin-right: 20rpx;
					}
				}
			}
		}

		.menu-box {
			width: 100%;
			margin: 28rpx 0 32rpx;

			.menu-item {
				text-align: center;
				font-size: 24rpx;
				color: #FFFFFF;

				image {
					width: 90rpx;
					height: 90rpx;
				}
			}
		}

		.menu-scroll-view {
			width: 100%;
			box-sizing: border-box;
			height: 204rpx;
			padding: 20rpx;
			white-space: nowrap;

			.menu-item {
				display: inline-block;
				vertical-align: top;
				width: 100rpx;
				text-align: center;
				font-size: 24rpx;
				color: #FFFFFF;
				margin-right: 58rpx;

				&:last-child {
					margin-right: 0;
				}

				image {
					width: 100rpx;
					height: 100rpx;
				}
			}
		}

		.bannar {
			width: 100%;
			height: 300rpx;
			padding: 20rpx 0;
			box-sizing: border-box;

			swiper,
			swiper-item,
			image {
				width: 100%;
				height: 100%;
				border-radius: 10rpx;
				background: none;
			}
		}

		.officialLabel {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 20rpx;

			>view {
				display: flex;
				align-items: center;

				image {
					width: 22rpx;
					height: 26rpx;
				}

				text {
					color: #AA8050;
					font-size: 22rpx;
					padding-left: 8rpx;
				}
			}
		}
	}

	.coordinate {
		width: 200rpx;
		height: 88rpx;
		display: flex;
		align-items: center;

		.text {
			flex: 1;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
			color: #fff;
		}
	}
</style>
